home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-12-04 | 7.7 KB | 182 lines | [TEXT/MPS ] |
- MacShell was written as an application shell to simplify getting a
- Macintosh application started. There is a large amount of code that
- a developer needs to write for a Macintosh application before
- even getting to the interesting stuff. MacShell is an attempt at
- reducing this initial coding effort.
-
- With 7.0 now upon us, this initial effort has grown. There are a number
- of new things that an application has to do in order to be 7.0 savvy.
-
- MacShell attempts to remove this burden from the developer by implementing
- the basics as completely as possible. The basics include the File and
- Edit menus, plus handling windows, printing, code for AppleEvente, etc.
-
- To implement the File and Edit menus, MacShell must know something about
- your document. If it didn't, menu items like printing wouldn't be able
- to be implemented for you.
-
- MacShell doesn't need to know much about the document or its structure.
- Most of what it needs to know about is outlined in the below structure:
-
-
- typedef struct {
- OSType sfType;
- Boolean docDirty;
- Boolean readOnly;
- short refNum;
- FSSpec fss;
- WindowPtr window;
- ImageProcPtr imageProc;
- ContentClickProcPtr contentClickProc;
- ContentKeyProcPtr contentKeyProc;
- InitContentProcPtr initContentProc;
- ResizeContentProcPtr resizeContentProc;
- DrawFrameProcPtr drawFrameProc;
- CalcFrameRgnProcPtr calcFrameRgnProc;
- short attributes;
- ControlHandle hScroll;
- ControlHandle vScroll;
- short hArrowVal;
- short vArrowVal;
- short hPageVal;
- short vPageVal;
- short hDocSize;
- short vDocSize;
- } FileStateRec;
-
-
- It needs to know if the document is dirty (has changed) so that it
- knows whether or not to put up a dialog when the user tries to close
- the window. It also needs to know if the user opened the document
- as a read-only document. (This can occur if you are opening a file
- over a network that has already been opened by another user.) It needs
- the file reference number and file specification (yawn). It needs to
- know the procedure you wish to use to update the window content and
- print. It needs to know what procedure you wish to use to initialize
- the content of the window. (Content initialization may mean adding
- controls to the content, for example.) If your window has document
- scrollbars, it needs to know how far to scroll for the line, and page
- parts of the control. It needs to know how big the document is.
-
- The fields from docDirty through calcFrameRgnProc are all initialized
- for you. These pertain to the document. The rest of the fields are
- not initialized until you create a window for the document. A document
- is first created without a window, and then you can give the document
- a window, if you wish. (A document that is only printed doesn't need
- a window, since it never becomes visible.)
-
- If you choose to give the document a window, you call DoNewWindow.
- DoNewWindow creates a window for the document passed it. If the
- window is successfully created, DoNewWindow then calls the procedure
- indicated by the field initContentProc. The default procedure is
- called InitContent, and unless you change it, this is what
- the field initContentProc holds.
-
- MacShell already is coded up to do this. If the user selects New or Open
- from the File menu, AppNewDocument or AppOpenDocument is first called.
- If that succeeds, DoNewWindow is called for that document. If that
- succeeds, the window then becomes visible for the user.
-
- The content of the window is drawn by the procedure pointed to by the
- field imageProc. The field imageProc is initialized to point to the
- procedure ImageDocument. This procedure pointer is used whenever the
- window needs updating or whenever the document needs printing. Just
- as you can override the initContentProc, you can override the imageProc
- by changing it after creating the document and prior to calling
- DoNewWindow. This allows you to have more than one document type for
- your application.
-
-
- The part that you need to do for file I/O is to replace the following
- functions in file2.c:
-
- AppFreeDocument();
- AppInitDocument();
- AppReadDocument();
- AppWriteDocument();
- AppDuplicateDocument();
-
- AppInitDocument is called by AppNewDocument. The default initialization
- has already been done. There may be more that you need to do for your
- document architecture. Your document may be a single big handle. If
- so, then AppInitDocument needs to create this handle. If you can't
- create it, then you need to return the appropriate error so that
- AppNewDocument knows that it failed.
-
- AppReadDocument is called by AppOpenDocument. AppOpenDocument first
- calls AppNewDocument to create a new document. If it succeeds, it
- then calls AppNewDocument to create a new empty document. If this
- succeeds, it then calls AppReadDocument. AppReadDocument is your
- code. You write the code that actually reads in the data. You read
- the data into the document structure. This structure is defined
- as follows:
-
-
- typedef struct {
- short version; /* The file format version. */
- Boolean printRecValid; /* True if print record has been created. */
- TPrint print; /* Print record for file. */
- short endVersPrintInfo; /* End version and print information. */
- } TheDoc;
-
-
- The first thing your code does is to read in the version and print
- record information. (AppReadDocument already has sample code to
- do this. Just keep the code.) You then read in the rest of your
- document into the portion of the structure starting after the field
- endLocalInfo. The application-specific portion of this structure
- for the MacShell sample is a text handle, followed by two TextEdit
- handles. Not all of this portion needs to be saved to disk. (In
- the MacShell sample, the data for the TextEdit handle is the only
- portion saved to disk.)
-
- To write out your document, just replace the appropriate code in
- the function AppWriteDocument. It will get called when needed.
-
- If you have multiple document types, you can reference the sfType
- field to determine which document type you are dealing with.
- Whenever a document is created via AppNewDocument or opened via
- AppOpenDocument, the OSType is saved in the field sfType. If there
- is custom initialization that needs to occur based on the document
- type, then AppInitDocument can reference sfType to determine which
- document type is being initialized.
-
-
- The final file I/O function that you need is AppDuplicateDocument.
- You might not even want this feature in your application. If not,
- then yank it from MacShell. If you want it, then add the code
- necessary to duplicate a document in the function.
-
-
-
- All you need at this point to try your application for the first
- time is an imaging procedure. Replace the code in the function
- ImageDocument with your own, and you are ready to try compiling
- your application. Given that you removed the sample data area
- from the document structure and replaced it with your own, you
- will most likely not compile. Let the compiler find the exceptions
- and then fix them. After this step, you should have a skeleton of
- your application that handles file I/O and printing.
-
- Once you have a skeleton running, you will wish to modify or replace
- the remaining procedure pointers that define the behavior of the
- document window. All of these functions will be found in the file
- window2.c
-
-
- To find the other areas that you will need to change, see the RoadMap
- file. It has bullet points marking the source files that you need
- to be concerned with.
-
-
- Another good way to get a global picture of MacShell is to read the
- ‘! MacShell.fn.descriptions’ file. This file lists all of the
- functions, just as MacShell.protos does, but it also has a function
- description of each and how it is used within MacShell.
-
-
-
- This should get you well on your way to using MacShell as a framework
- for your application.
-
-